﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ClassLibrary.Data;
using ClassLibrary.DAO;

public partial class Admin_ucControl_ucListChip : System.Web.UI.UserControl
{
    TblChipDAO chipDAO = new TblChipDAO(Global.CONNECTION_STRING);
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session[Global.SESSION_ADMIN_USER] == null)
            {
                Response.Redirect("~/Admin/Login.aspx");
            }
            LoadChipList();
        }
    }

    private void LoadChipList()
    {
        try
        {
            grdProduct.DataSource = chipDAO.GetChipList();
            grdProduct.DataBind();
        }
        catch(Exception ex)
        {
            Session[Global.SESSION_ERROR] = ex;
            Response.Redirect(Global.ERROR_PAGE_ADMIN);
        }
    }
    protected void btnModelDelete_Click(object sender, ImageClickEventArgs e)
    {
        // string id = Request.QueryString["id"];
        bool flag = false;
        try
        {

            //TblModel model = new TblModel();
            TblChip chip = new TblChip();
            chip.IDChip = Convert.ToInt32(((ImageButton)sender).CommandArgument);
            int IDDelete = Convert.ToInt32(((ImageButton)sender).CommandArgument);
            chipDAO.DeleteChip(IDDelete);
            flag = true;
        }
        catch (Exception ex)
        {
            Session[Global.SESSION_ERROR] = ex;
            Response.Redirect(Global.ERROR_PAGE_ADMIN);
        }
        if (flag)
        {
            Response.Redirect("~/Admin/ListProducts.aspx");
        }
    }
    protected void grdProduct_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grdProduct.PageIndex = e.NewPageIndex;
        LoadChipList();
    }
}
